package org.stayfool.client.util.future;

import io.netty.handler.codec.mqtt.MqttConnAckMessage;
import io.netty.handler.codec.mqtt.MqttConnectReturnCode;
import org.stayfool.client.event.OneTimeEventCallBack;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * Created by Stayfool on 2017/2/22.
 */
public class ConnectFuture extends AbstractFuture<MqttConnAckMessage>
        implements Future<MqttConnAckMessage>, OneTimeEventCallBack<MqttConnAckMessage> {

    private final AtomicBoolean isConnect;

    public ConnectFuture(AtomicBoolean isConnect) {
        this.isConnect = isConnect;
    }

    @Override
    public void callback(MqttConnAckMessage msg) {
        isConnect.set(this.msg.variableHeader().connectReturnCode().equals(MqttConnectReturnCode.CONNECTION_ACCEPTED));
        setDone(msg);
    }
}
